Skip to content

Read Consistency Strategy: Adds hub region header for LastCommittedSingleWriteRegion strategy.#5815

Merged
microsoft-github-policy-service[bot] merged 26 commits into
mainfrom
users/aavasthy/ReadConsistencyWithHubRegionheader
May 13, 2026
Merged

Read Consistency Strategy: Adds hub region header for LastCommittedSingleWriteRegion strategy.#5815
microsoft-github-policy-service[bot] merged 26 commits into
mainfrom
users/aavasthy/ReadConsistencyWithHubRegionheader

Conversation

@aavasthy
Copy link
Copy Markdown
Contributor

@aavasthy aavasthy commented Apr 28, 2026

Pull Request Template

Description

Direct package update to 4.43.1:
Merged PRs:

Update logic for ReadConsistencyStrategy header parsing and fallback improvements
https://msdata.visualstudio.com/CosmosDB/_git/CosmosDB/pullrequest/2075563

Add LastCommittedSingleWriteRegion Read Consistency Strategy
https://msdata.visualstudio.com/CosmosDB/_git/CosmosDB/pullrequest/2089383

DTC Status Codes and SubStatus Codes Generation
https://msdata.visualstudio.com/CosmosDB/_git/CosmosDB/pullrequest/2030762?

This PR introduces a new LastCommittedWriteRegion value to the ReadConsistencyStrategy enum, enabling reads to be routed to the hub (write) region so they always reflect the most recent writes regardless of which region the client is connected to. When this strategy is set either at the client or request level and the operation is a read (point read, query, change feed, or ReadMany), the SDK additionally sets the ShouldProcessOnlyInHubRegion header so the backend routes the request to the write region. The header is only applied for read operations and is not set for writes.

Hedging request with hub region header:
When CrossRegionHedgingAvailabilityStrategy is active, the primary request may discover the hub region mid-flight
(after 2× 404/1002 triggers addHubRegionProcessingOnlyHeader = true in ClientRetryPolicy). Hedged requests are
clones of the original and run with their own ClientRetryPolicy instance, so they would normally repeat the entire
hub discovery cycle independently. To avoid this redundant retry overhead, we introduce a
CrossRegionAvailabilityContext — a lightweight shared object with a volatile bool
ShouldAddHubRegionProcessingOnlyHeader flag. This context is injected into RequestMessage.Properties before the
clone loop in CrossRegionHedgingAvailabilityStrategy. Since Clone() performs a shallow dictionary copy, all clones
(primary + hedges) share the same CrossRegionAvailabilityContext reference. When the primary's ClientRetryPolicy
sets the hub flag after 2× 404/1002, it also sets the flag on the shared context. Each hedge's
ClientRetryPolicy.OnBeforeSendRequest reads this shared flag on every attempt and attaches the
x-ms-cosmos-hub-region-processing-only header immediately — without needing to go through its own 404/1002
discovery.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Closing issues

To automatically close an issue: closes #IssueNumber

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@NaluTripician
Copy link
Copy Markdown
Contributor

@sdkReviewAgent-2

Comment thread Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs Outdated
@xinlian12
Copy link
Copy Markdown
Member

Review complete (55:02)

Posted 2 inline comment(s).

Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage

Copy link
Copy Markdown
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we always route requests to hub region, what happens if customers set this in case of multi-writer account?

Comment thread Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs Outdated
Comment thread Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs Outdated
Copy link
Copy Markdown
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hubregion processing should only be triggered by a single ReadConsistencyStartegy enum value - like LastCommittedWriteRegion or similar. Not for all ReadConsistencyStartegies for sure!

…stencyStrategy and only for read operation type
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@aavasthy aavasthy force-pushed the users/aavasthy/ReadConsistencyWithHubRegionheader branch from b9070dd to dac78b4 Compare May 6, 2026 07:25
@aavasthy aavasthy force-pushed the users/aavasthy/ReadConsistencyWithHubRegionheader branch from 7896535 to 9ac50cd Compare May 11, 2026 23:44
Comment thread Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs Outdated
Copy link
Copy Markdown
Contributor

@NaluTripician NaluTripician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes might be needed but other than that LGTM

Comment thread Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs
Comment thread Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs
Comment thread Directory.Build.props
NaluTripician
NaluTripician previously approved these changes May 12, 2026
@aavasthy aavasthy changed the title Read Consistency Strategy: Adds hub region header for LastCommittedWriteRegion strategy. Read Consistency Strategy: Adds hub region header for LastCommittedSingleWriteRegion strategy. May 13, 2026
Copy link
Copy Markdown
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changelog entry.

@aavasthy aavasthy dismissed stale reviews from Meghana-Palaparthi and NaluTripician via 69b12ad May 13, 2026 19:01
@aavasthy
Copy link
Copy Markdown
Contributor Author

Requesting changelog entry.

updated changelog

Copy link
Copy Markdown
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @aavasthy for adding the changelog entry :)

NaluTripician added a commit that referenced this pull request May 13, 2026
Adds a new Unreleased Preview section (per the pattern established in PR #5815) with a Fixed entry for PR #5844. Customer-facing description focuses on the symptom (premature OperationCanceledException preempting cross-region failover during metadata-cache reads) rather than the implementation detail (the new MetadataDetachedExecutor).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@microsoft-github-policy-service microsoft-github-policy-service Bot merged commit 66a3883 into main May 13, 2026
32 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot deleted the users/aavasthy/ReadConsistencyWithHubRegionheader branch May 13, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge Enables automation to merge PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants